package com.facebook.imagepipeline.animated.impl;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.SystemClock;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import com.facebook.common.logging.FLog;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableCachingBackend;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableDiagnostics;
import com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil;

public class AnimatedDrawableDiagnosticsImpl
  implements AnimatedDrawableDiagnostics
{
  private static final Class<?> TAG = AnimatedDrawableDiagnostics.class;
  private AnimatedDrawableCachingBackend mAnimatedDrawableBackend;
  private final AnimatedDrawableUtil mAnimatedDrawableUtil;
  private final TextPaint mDebugTextPaint;
  private final DisplayMetrics mDisplayMetrics;
  private final RollingStat mDrawnFrames;
  private final RollingStat mDroppedFramesStat;
  private long mLastTimeStamp;
  private final StringBuilder sbTemp;

  public AnimatedDrawableDiagnosticsImpl(AnimatedDrawableUtil paramAnimatedDrawableUtil, DisplayMetrics paramDisplayMetrics)
  {
    this.mAnimatedDrawableUtil = paramAnimatedDrawableUtil;
    this.mDisplayMetrics = paramDisplayMetrics;
    this.mDroppedFramesStat = new RollingStat();
    this.mDrawnFrames = new RollingStat();
    this.sbTemp = new StringBuilder();
    this.mDebugTextPaint = new TextPaint();
    this.mDebugTextPaint.setColor(-16776961);
    this.mDebugTextPaint.setTextSize(convertDpToPx(14));
  }

  private int convertDpToPx(int paramInt)
  {
    return (int)TypedValue.applyDimension(1, paramInt, this.mDisplayMetrics);
  }

  public void drawDebugOverlay(Canvas paramCanvas, Rect paramRect)
  {
    int i = this.mDroppedFramesStat.getSum(10);
    int j = this.mDrawnFrames.getSum(10);
    int k = j + i;
    int m = convertDpToPx(10);
    int n = m;
    int i1 = convertDpToPx(20);
    int i2 = convertDpToPx(5);
    if (k > 0)
    {
      int i5 = j * 100 / k;
      this.sbTemp.setLength(0);
      this.sbTemp.append(i5);
      this.sbTemp.append("%");
      paramCanvas.drawText(this.sbTemp, 0, this.sbTemp.length(), n, i1, this.mDebugTextPaint);
      n = i2 + (int)(n + this.mDebugTextPaint.measureText(this.sbTemp, 0, this.sbTemp.length()));
    }
    int i3 = this.mAnimatedDrawableBackend.getMemoryUsage();
    this.sbTemp.setLength(0);
    this.mAnimatedDrawableUtil.appendMemoryString(this.sbTemp, i3);
    float f = this.mDebugTextPaint.measureText(this.sbTemp, 0, this.sbTemp.length());
    if (f + n > paramRect.width())
    {
      n = m;
      i1 = (int)(i1 + (this.mDebugTextPaint.getTextSize() + i2));
    }
    paramCanvas.drawText(this.sbTemp, 0, this.sbTemp.length(), n, i1, this.mDebugTextPaint);
    int i4 = i2 + (int)(f + n);
    this.sbTemp.setLength(0);
    this.mAnimatedDrawableBackend.appendDebugOptionString(this.sbTemp);
    if (this.mDebugTextPaint.measureText(this.sbTemp, 0, this.sbTemp.length()) + i4 > paramRect.width())
    {
      i4 = m;
      i1 = (int)(i1 + (this.mDebugTextPaint.getTextSize() + i2));
    }
    paramCanvas.drawText(this.sbTemp, 0, this.sbTemp.length(), i4, i1, this.mDebugTextPaint);
  }

  public void incrementDrawnFrames(int paramInt)
  {
    this.mDrawnFrames.incrementStats(paramInt);
  }

  public void incrementDroppedFrames(int paramInt)
  {
    this.mDroppedFramesStat.incrementStats(paramInt);
    if (paramInt > 0)
      FLog.v(TAG, "Dropped %d frames", Integer.valueOf(paramInt));
  }

  public void onDrawMethodBegin()
  {
    this.mLastTimeStamp = SystemClock.uptimeMillis();
  }

  public void onDrawMethodEnd()
  {
    long l = SystemClock.uptimeMillis() - this.mLastTimeStamp;
    FLog.v(TAG, "draw took %d", Long.valueOf(l));
  }

  public void onNextFrameMethodBegin()
  {
    this.mLastTimeStamp = SystemClock.uptimeMillis();
  }

  public void onNextFrameMethodEnd()
  {
    long l = SystemClock.uptimeMillis() - this.mLastTimeStamp;
    if (l > 3L)
      FLog.v(TAG, "onNextFrame took %d", Long.valueOf(l));
  }

  public void onStartMethodBegin()
  {
    this.mLastTimeStamp = SystemClock.uptimeMillis();
  }

  public void onStartMethodEnd()
  {
    long l = SystemClock.uptimeMillis() - this.mLastTimeStamp;
    if (l > 3L)
      FLog.v(TAG, "onStart took %d", Long.valueOf(l));
  }

  public void setBackend(AnimatedDrawableCachingBackend paramAnimatedDrawableCachingBackend)
  {
    this.mAnimatedDrawableBackend = paramAnimatedDrawableCachingBackend;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.imagepipeline.animated.impl.AnimatedDrawableDiagnosticsImpl
 * JD-Core Version:    0.6.2
 */